#!/bin/bash

helpFunction()
{
   echo ""
   echo "Usage: $0 -m <message_to_push> [-p] 1"
   exit 1 # Exit script after printing help
}

push=0

while getopts "m:p:" opt
do
   case "$opt" in
      m) message="$OPTARG" ;;
      p) push="$OPTARG";;
      ?) helpFunction ;; # Print helpFunction in case parameter is non-existent
   esac
done

if [ -z "$message" ]
then
   echo 'Missing -m' >&2
   helpFunction
   exit 2
fi

cur_branch=$(git branch --show-current)
# echo $cur_branch

# echo $branch
# echo $message
msg='"'$message'"'
# echo $message
# echo $msg
# echo $push

git add --all
git commit --message $msg

if [ $push -eq 1 ]
then
  git push origin $cur_branch
fi

